package com.opencgl.utils;

import org.apache.mina.core.buffer.IoBuffer;

/**
 * @author Chance.W
 * @date 2020/2/7-10:11
 */
public class MsgTxHead implements MsgPart {
    public static final String TxBeg = "TxBeg ";
    public static final String TxCon = "TxCon ";
    public static final String TxEnd = "TxEnd ";
    public static final int MSG_TX_HEAD_LEN = 18;
    public Integer id;
    public String word;

    public MsgTxHead() {
    }

    public MsgTxHead(IoBuffer buf) {
        this.id = Xx.getHexInt(buf, 8);
        byte[] word = new byte[6];
        buf.get(word);
        this.word = new String(word);
    }

    @Override
    public byte[] toByte() {
        IoBuffer buffer = IoBuffer.allocate(18);
        buffer.put(Xx.intToHexByte8(this.id));
        buffer.put(this.word.getBytes());
        buffer.putInt(0);
        return buffer.array();
    }
}

